package com.qcloud.cos.request;

import com.qcloud.cos.common_utils.CommonParamCheckUtils;
import com.qcloud.cos.exception.ParamException;
import com.qcloud.cos.meta.InsertOnly;

import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Created by yanwc on 2016/8/25.
 */
public class UploadFileStreamRequest extends AbstractBaseRequest {

    private String fileName;

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    // 上传文件的属性信息
    private String bizAttr;

    private InputStream stream;

    public String getBizAttr() {
        return bizAttr;
    }

    public void setBizAttr(String bizAttr) {
        this.bizAttr = bizAttr;
    }

    public InsertOnly getInsertOnly() {
        return insertOnly;
    }

    public void setInsertOnly(InsertOnly insertOnly) {
        this.insertOnly = insertOnly;
    }

    private InsertOnly insertOnly = InsertOnly.NO_OVER_WRITE;

    public UploadFileStreamRequest(String bucketName, String cosPath, InputStream stream,String fileName) {
        super(bucketName, cosPath);
        this.stream = stream;
        this.fileName= fileName;
    }

    public UploadFileStreamRequest(String bucketName, String cosPath, FileInputStream stream, String bizAttr,String fileName) {
        super(bucketName, cosPath);
        this.bizAttr = bizAttr;
        this.stream =stream;
        this.fileName = fileName;
    }

    @Override
    public void check_param() throws ParamException {
        super.check_param();
        CommonParamCheckUtils.AssertLegalCosFilePath(this.getCosPath());
        CommonParamCheckUtils.AssertNotNull("biz_attr", this.bizAttr);
        CommonParamCheckUtils.AssertNotNull("insertOnly", this.insertOnly);
        CommonParamCheckUtils.AssertNotNull("fileName",this.fileName);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        sb.append(",fileName:").append(this.fileName);
        sb.append(", bizAttr:").append(getMemberStringValue(this.bizAttr));
        sb.append(", insertOnly:");
        if (this.insertOnly == null) {
            sb.append("null");
        } else {
            sb.append(this.insertOnly.ordinal());
        }
        return sb.toString();
    }

    public InputStream getStream() {
        return stream;
    }

    public void setStream(InputStream stream) {
        this.stream = stream;
    }
}
